/*
 * Copyright (C) 2012-2013  Romain DUBOIS
 * 
 * This file is part of NeMoS - Network and Modular Software
 * 
 * NeMoS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * NeMoS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NeMoS.  If not, see <http://www.gnu.org/licenses/>.
 */
package nemos.sample.network.internal;

import nemos.remote.util.RemoteUtil;
import nemos.sample.network.FrameworkDescription;
import nemos.sample.network.IConnectedFramework;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;

/**
 * ConnectedFrameworkImpl : The simple connected framework implementation.
 * 
 * @author Romain DUBOIS
 */
@Service(IConnectedFramework.class)
@Property(name = Constants.SERVICE_EXPORTED_INTERFACES, value = "*")
@Component(name = "nemos.sample.network.ConnectedFramework")
public class ConnectedFrameworkImpl implements IConnectedFramework {

    /** The framework description */
    private final FrameworkDescription mDescription;

    /**
     * Constructor.
     */
    public ConnectedFrameworkImpl() {
        super();

        mDescription = new FrameworkDescription();
    }

    /**
     * Start the component.
     * 
     * @param pContext
     *            The bundle context
     */
    @Activate
    public void start(final BundleContext pContext) {
        mDescription.setHostName(RemoteUtil.findHostName(null));
        mDescription.setOsArch(pContext.getProperty("os.arch")); //$NON-NLS-1$
        mDescription.setOsName(pContext.getProperty("os.name")); //$NON-NLS-1$
        mDescription.setOsVersion(pContext.getProperty("os.version")); //$NON-NLS-1$
        mDescription.setSystemUserName(pContext.getProperty("user.name")); //$NON-NLS-1$
    }

    /**
     * {@inheritDoc}
     * 
     * @see nemos.sample.network.IConnectedFramework#getDescription()
     */
    @Override
    public FrameworkDescription getDescription() {
        return mDescription;
    }
}
